import SiderbarNoteItem from "@/components/SiderbarNoteItem";
import { getAllNotes } from "@/lib/redis";

export default async function SidebarNoteList() {
  const notes = await getAllNotes();
  const arr = Object.entries(notes);

  if (arr.length === 0) {
    return <div className="notes-empty">
      {"No notes create yet!"}
    </div>;
  }

  return (
    <ul className="notes-list">
      {arr.map(([noteId, note]) => {
        const { title, updateTime } = JSON.parse(note);
        return (
          <li key={noteId}>
            {/* <header className="sidebar-note-header">
                  <strong>{title}</strong>
                  <small>{dayjs(updateTime).format('YYYY-MM-DD hh:mm:ss')}</small>
                </header> */}

            <SiderbarNoteItem noteId={noteId} note={JSON.parse(note)} />
          </li>
        );
      })}
    </ul>
  );
}
